<?php

class Html{
    
    private $_title;
    private $_meta;
    private $_text;

    public function __construct($file)
    {
        $this->_title = null;
        $this->_meta = array();
        $this->_text = null;
        $this->_htmlAnalyzer($file);
    }

    public function getTitle()
    {
        return $this->_title;
    }

    public function getMeta($key)
    {
        return $this->_meta[$key];
    }

    public function getAllMeta()
    {
        return $this->_meta;
    }

    public function setTitle($title)
    {
        $this->_title = $title;
    }

    public function setMeta($key,$meta)
    {
        $this->_meta[$key] = $meta;
    }

    public function getText()
    {
        return $this->_text;
    }

    public function setText($text)
    {
        $this->_text = $text;
    }

    private function _htmlAnalyzer($file)
    {
        $sText = '';
        while(!feof($file))
        {
            $linea = fgets($file, 4096);
            if(strpos($linea, "<meta name="))
            {
                $xml = simplexml_load_string($linea);
                $node = $xml->attributes();
                $this->setMeta((string)$node['name'], (string)$node['content']);
            }
            if(strpos($linea, "<title"))
            {
                $this->setTitle(trim(strip_tags($linea)));
            }
            if(!empty($linea))
            {
                $sText .= strip_tags($linea);
            }    
        }
        $this->setText($sText);
    }
        
}

